package com.xrh.xdemo.service.controllers;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xrh.core.bean.CommonPage;
import com.xrh.core.bean.CommonResult;
import com.xrh.core.enums.ResultCodeEnum;
import com.xrh.core.exceptions.BusinessException;
import com.xrh.xdemo.api.dto.extend.OperateTraceDTO;
import com.xrh.xdemo.api.request.queryRequest.OperateTraceQueryRequest;
import com.xrh.xdemo.service.service.OperateTraceService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@Api(tags="操作痕迹API")
@RestController
@RequestMapping("operateTrace")
@Slf4j
public class OperateTraceController {

    @Resource
    private OperateTraceService operateTraceService;

   	/**
   	 * @function 删除操作痕迹
   	 * @author 肖荣辉
   	 * @date 2024-01-05 16:19:58
   	*/
   	@ApiOperation("删除操作痕迹")
   	@ApiImplicitParam(name = "id", value = "主键ID", required = true)
   	@PostMapping("/deleteOperateTraceById")
   	public CommonResult<Void> deleteOperateTraceById(Long  id){
   		
   		try {
   			
   			if(id == null)
   				return CommonResult.failed("id不能为空");
   			
   			operateTraceService.deleteOperateTraceById(id);
   			
   			return CommonResult.success();
   			
   		} catch (BusinessException e) {
   			return CommonResult.failed(e.getCode() , e.getMsg());
   		} catch (Exception e) {
   			log.error("deleteOperateTrace发生错误 ==> " , e);
   			return CommonResult.failed(ResultCodeEnum.SYSTEM_FAILED);
   		} 
   		
   	}
   	
   	
   	/**
   	 * @function 根据ID获取对象
   	 * @param id
   	 * @author 肖荣辉
   	 * @date 2024-01-05 16:19:58
   	*/
   	@ApiOperation("获取操作痕迹信息")
    @ApiImplicitParam(name = "id", value = "主键ID", required = true)
   	@PostMapping("/findOperateTraceById")
   	public CommonResult<OperateTraceDTO> findOperateTraceById(Long id){
   		
   		try {
   			
   			if(id == null)
   				return CommonResult.failed("id不能为空");
   				
   			OperateTraceDTO dto =  operateTraceService.findOperateTraceById(id);
   			
   			return CommonResult.success(dto);
   			
   		} catch (BusinessException e) {
   			return CommonResult.failed(e.getCode() , e.getMsg());
   		} catch (Exception e) {
   			log.error("findOperateTraceById 发生错误 ==> " , e);
   			return CommonResult.failed(ResultCodeEnum.SYSTEM_FAILED);
   		} 
   		
   		
   	}
   	
   	/**
   	 * @function 查询操作痕迹列表
   	 * @author 肖荣辉
   	 * @param operateTraceQueryRequest
   	 * @date 2024-01-05 16:19:58
   	*/
   	@ApiOperation("获取操作痕迹列表")
   	@PostMapping("/findOperateTraceList")
   	public CommonResult<CommonPage<OperateTraceDTO>> findOperateTraceList(@RequestBody  OperateTraceQueryRequest operateTraceQueryRequest){
   		
   		try {
   			 
   			return operateTraceService.findOperateTraceList(operateTraceQueryRequest);
   			
   		} catch (BusinessException e) {
   			return CommonResult.failed(e.getCode() , e.getMsg());
   		} catch (Exception e) {
   			log.error("findOperateTraceList 发生错误 ==> " , e);
   			return CommonResult.failed(ResultCodeEnum.SYSTEM_FAILED);
   		} 
   		
   	}

}
